



clear 
set scheme lean2, permanent
global pm = char(177)
set more off

set more off
clear all

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  
 
global path_cps "\data\cps" // download and copy cps data into this folder.
global path_output "\data\output"

*** 1) By education
*******************

cd "$path_cps"
use "morg_clean.dta", clear
cd "$path_output"

keep if age>=25 & age<=55
replace unemployed=. if outoflaborforce==.

/* Note:
- In the RN sample we only have people in FT-employment. We cannot make the CPS sample fully comparable.
  Therefore we start at an age where full-time education should be completed for most individuals.
  Also we end at an age where most people should not be retired yet.
*/


collapse (mean) employed unemployed [aweight=weight], by(year month atleastbachelor) cw

gen employed_sa=0

reg employed i.month if atleastbachelor==0
predict employed_res, resid, if atleastbachelor==0
mat b=e(b)
replace employed_sa=b[1,13] + employed_res if atleastbachelor==0
drop employed_res

reg employed i.month if atleastbachelor==1
predict employed_res, resid, if atleastbachelor==1
mat b=e(b)
replace employed_sa=b[1,13] + employed_res if atleastbachelor==1
drop employed_res

gen unemployed_sa=0

reg unemployed i.month if atleastbachelor==0
predict unemployed_res, resid, if atleastbachelor==0
mat b=e(b)
replace unemployed_sa=b[1,13] + unemployed_res if atleastbachelor==0
drop unemployed_res

reg unemployed i.month if atleastbachelor==1
predict unemployed_res, resid, if atleastbachelor==1
mat b=e(b)
replace unemployed_sa=b[1,13] + unemployed_res if atleastbachelor==1
drop unemployed_res

gen t=month + (year-2000)*12

gen greatrecession=(t>=95&t<=113)

local xlab 48 "2004" 60 "2005" 72 "2006" 84 "2007" 96 "2008" 108 "2009" 120 "2010" 132 "2011" 144 "2012" 156 "2013" 168 "2014" 180 "2015" 192 "2016"

twoway ///
(line employed_sa t if atleastbachelor==0, lpattern(solid) lcolor(black)) ///
(line employed_sa t if atleastbachelor==1, lpattern(shortdash) lcolor(black)) ///
if year>=2004 & year<=2015, ///
xtitle("Year", size(medium)) ytitle("Employment rate", size(small)) xlab(`xlab', angle(45)) legend(cols(1) label(1 "Below college") label(2 "College")) ///
xline(95, lcolor(gs9)) xline(113, lcolor(gs9))
graph export "greatrecession_empl_educ.pdf", replace
graph save "greatrecession_empl_educ.gph", replace

twoway ///
(line unemployed_sa t if atleastbachelor==0, lpattern(solid) lcolor(black)) ///
(line unemployed_sa t if atleastbachelor==1, lpattern(shortdash) lcolor(black)) ///
if year>=2004 & year<=2015, ///
xtitle("Year", size(medium)) ytitle("Unemployment rate", size(small)) xlab(`xlab', angle(45)) legend(cols(1) label(1 "Below college") label(2 "College")) ///
xline(95, lcolor(gs9)) xline(113, lcolor(gs9)) yscale(range(0(0.02)0.1)) ylabel(0(0.02)0.1)
graph export "greatrecession_unempl_educ.pdf", replace
graph save "greatrecession_unempl_educ.gph", replace


*** 2) By gender
****************

cd "$path_cps"
use "morg_clean.dta", clear
cd "$path_output"

keep if age>=25 & age<=55
replace unemployed=. if outoflaborforce==.

/* Note:
- In the RN sample we only have people in FT-employment. We cannot make the CPS sample fully comparable.
  Therefore we start at an age where full-time education should be completed for most individuals.
  Also we end at an age where most people should not be retired yet.
*/

collapse (mean) employed unemployed [aweight=weight], by(year month female) cw

gen employed_sa=0

reg employed i.month if female==0
predict employed_res, resid, if female==0
mat b=e(b)
replace employed_sa=b[1,13] + employed_res if female==0
drop employed_res

reg employed i.month if female==1
predict employed_res, resid, if female==1
mat b=e(b)
replace employed_sa=b[1,13] + employed_res if female==1
drop employed_res

gen unemployed_sa=0

reg unemployed i.month if female==0
predict unemployed_res, resid, if female==0
mat b=e(b)
replace unemployed_sa=b[1,13] + unemployed_res if female==0
drop unemployed_res

reg unemployed i.month if female==1
predict unemployed_res, resid, if female==1
mat b=e(b)
replace unemployed_sa=b[1,13] + unemployed_res if female==1
drop unemployed_res

gen t=month + (year-2000)*12

gen greatrecession=(t>=95&t<=113)

local xlab 48 "2004" 60 "2005" 72 "2006" 84 "2007" 96 "2008" 108 "2009" 120 "2010" 132 "2011" 144 "2012" 156 "2013" 168 "2014" 180 "2015" 192 "2016"

twoway ///
(line employed_sa t if female==0, lpattern(solid) lcolor(black)) ///
(line employed_sa t if female==1, lpattern(shortdash) lcolor(black)) ///
if year>=2004 & year<=2015, ///
xtitle("Year", size(medium)) ytitle("Employment rate", size(small)) xlab(`xlab', angle(45)) legend(cols(1) label(1 "Male") label(2 "Female")) ///
xline(95, lcolor(gs9)) xline(113, lcolor(gs9))
graph export "greatrecession_empl_gender.pdf", replace
graph save "greatrecession_empl_gender.gph", replace


twoway ///
(line unemployed_sa t if female==0, lpattern(solid) lcolor(black)) ///
(line unemployed_sa t if female==1, lpattern(shortdash) lcolor(black)) ///
if year>=2004 & year<=2015, ///
xtitle("Year", size(medium)) ytitle("Unemployment rate", size(small)) xlab(`xlab', angle(45)) legend(cols(1) label(1 "Male") label(2 "Female")) ///
xline(95, lcolor(gs9)) xline(113, lcolor(gs9)) yscale(range(0(0.02)0.1)) ylabel(0(0.02)0.1)
graph export "greatrecession_unempl_gender.pdf", replace
graph save "greatrecession_unempl_gender.gph", replace


*** 3) By age
*************

cd "$path_cps"
use "morg_clean.dta", clear
cd "$path_output"

keep if age>=25 & age<=55
replace unemployed=. if outoflaborforce==.


/* Note:
- In the RN sample we only have people in FT-employment. We cannot make the CPS sample fully comparable.
  Therefore we start at an age where full-time education should be completed for most individuals.
  Also we end at an age where most people should not be retired yet.
*/

gen old=(age>=45)

collapse (mean) employed unemployed [aweight=weight], by(year month old) cw

gen employed_sa=0

reg employed i.month if old==0
predict employed_res, resid, if old==0
mat b=e(b)
replace employed_sa=b[1,13] + employed_res if old==0
drop employed_res

reg employed i.month if old==1
predict employed_res, resid, if old==1
mat b=e(b)
replace employed_sa=b[1,13] + employed_res if old==1
drop employed_res

gen unemployed_sa=0

reg unemployed i.month if old==0
predict unemployed_res, resid, if old==0
mat b=e(b)
replace unemployed_sa=b[1,13] + unemployed_res if old==0
drop unemployed_res

reg unemployed i.month if old==1
predict unemployed_res, resid, if old==1
mat b=e(b)
replace unemployed_sa=b[1,13] + unemployed_res if old==1
drop unemployed_res

gen t=month + (year-2000)*12

gen greatrecession=(t>=95&t<=113)

local xlab 48 "2004" 60 "2005" 72 "2006" 84 "2007" 96 "2008" 108 "2009" 120 "2010" 132 "2011" 144 "2012" 156 "2013" 168 "2014" 180 "2015" 192 "2016"

twoway ///
(line employed_sa t if old==0, lpattern(solid) lcolor(black)) ///
(line employed_sa t if old==1, lpattern(shortdash) lcolor(black)) ///
if year>=2004 & year<=2015, ///
xtitle("Year", size(medium)) ytitle("Employment rate", size(small)) xlab(`xlab', angle(45)) legend(cols(1) label(1 "Age 25-44") label(2 "Age 45-55")) ///
xline(95, lcolor(gs9)) xline(113, lcolor(gs9))
graph export "greatrecession_empl_age.pdf", replace
graph save "greatrecession_empl_age.gph", replace

twoway ///
(line unemployed_sa t if old==0, lpattern(solid) lcolor(black)) ///
(line unemployed_sa t if old==1, lpattern(shortdash) lcolor(black)) ///
if year>=2004 & year<=2015, ///
xtitle("Year", size(medium)) ytitle("Unemployment rate", size(small)) xlab(`xlab', angle(45)) legend(cols(1) label(1 "Age 25-44") label(2 "Age 45-55")) ///
xline(95, lcolor(gs9)) xline(113, lcolor(gs9)) yscale(range(0(0.02)0.1)) ylabel(0(0.02)0.1)
graph export "greatrecession_unempl_age.pdf", replace
graph save "greatrecession_unempl_age.gph", replace


graph combine "greatrecession_empl_educ" "greatrecession_empl_gender" "greatrecession_empl_age", row(3) xcommon 
graph export  "CPS_empl_over.pdf", replace




graph combine "greatrecession_unempl_educ" "greatrecession_unempl_gender" "greatrecession_unempl_age", row(3) xcommon 
graph export  "CPS_unempl_over.pdf", replace









